package com.twohand.admin.Service.impl;

import com.twohand.admin.Entity.RoleMenu;
import com.twohand.admin.Mapper.RoleMenuMapper;
import com.twohand.admin.Service.RoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleMenuServiceImpl implements RoleMenuService {
    @Autowired
    RoleMenuMapper roleMenuMapper;
    @Override
    public Boolean deleteByRoleId(Integer id) {
        return roleMenuMapper.deleteByRoleId(id) > 0;
    }

    @Override
    public Boolean batchInsertByMenuId(List<Integer> menuIdList, Integer roleId) {
        //批量插入
        for(Integer i : menuIdList){
            // 构建对象
            RoleMenu roleMenu = new RoleMenu();
            roleMenu.setMenuId(i);
            roleMenu.setRoleId(roleId);
            if(roleMenuMapper.insert(roleMenu)==0){
                return false;
            }

        }
        return true;
    }
}
